package com.antt.cn.test2.uis.activities;

import android.view.View;
import android.widget.TextView;

import com.antt.cn.test2.R;
import com.antt.cn.test2.uis.base.BaseActivity;
import com.antt.cn.test2.utils.AntLog;

import butterknife.BindView;
import butterknife.ButterKnife;
import io.reactivex.Observable;
import io.reactivex.Observer;
import io.reactivex.annotations.NonNull;
import io.reactivex.disposables.Disposable;

/**
 * Created by Ant on 2017/5/31  19:19
 * <p>
 * <p>
 *
 * @version 1.0.0
 * @auther Ant
 */

public class Test09 extends BaseActivity implements View.OnClickListener {

    @BindView(R.id.ac_test09_textView)
    TextView text;

    private Observable<String> observable;
    private Observer<String> observer;


    @Override
    public int getLayoutId() {
        return R.layout.ac_test09_layout;
    }

    @Override
    public void initView() {
        ButterKnife.bind(this);
    }

    @Override
    public void initData() {
        observable = new Observable<String>() {
            @Override
            protected void subscribeActual(Observer<? super String> observer) {
                observer.onNext("hello");
                observer.onNext("word");
                observer.onComplete();
            }
        };
        observer = new Observer<String>() {
            @Override
            public void onSubscribe(@NonNull Disposable d) {

            }

            @Override
            public void onNext(@NonNull String s) {
                AntLog.i("onNext=" + s);
                text.setText("sss+s==" + s);
            }

            @Override
            public void onError(@NonNull Throwable e) {

            }

            @Override
            public void onComplete() {

            }
        };
        observable.subscribe(observer);

    }

    @Override
    public void initListener() {

    }


    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.ac_test09_obt01:
                new Observable<String>() {

                    @Override
                    protected void subscribeActual(Observer<? super String> observer) {
                        observer.onNext("wuliwala");
                        observer.onNext("wuliwala ahahahaha...");
                        observer.onComplete();
                    }
                }.subscribe(observer);
                break;
        }
    }
}
